package cn.itcast.erp.annotation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author:周昌洋
 * @time:2019/06/15
 */

public class CheckDateImp implements ConstraintValidator<CheckDate,String> {
    private String regular = "";

    @Override
    public void initialize(CheckDate constraintAnnotation) {
        regular = constraintAnnotation.regexp();
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if ("".equals(value)||value==null) {
            return true;
        }
        Pattern r = Pattern.compile(regular);
        Matcher m = r.matcher(value);
        boolean b = m.find();
        return b;
    }
}
